{
   window.comboxOperator = new Object();
}

comboxOperator.addOption = function(combox,value,text)
{
    combox.options[combox.options.length] = new Option(text,value);
};

comboxOperator.setOption = function(combox,value,text,index)
{
    var option = combox.options[index];
    option.value = value;
    option.text = text;
};

comboxOperator.setOptionText = function(combox,value,text)
{
    for(var i=0;i<combox.options.length;i++)
    {
       var option = combox.options[i];
       if(option.value ==  value)
       {
         option.text = text;
         break;
       }
    }
};

comboxOperator.getOptionIndex = function(combox,value)
{
    for(var i=0;i<combox.options.length;i++)
    {
       var option = combox.options[i];
       if(option.value ==  value)
       {
          return i;
       }
    }
};

comboxOperator.removeOption = function(combox,index)
{
    combox.options[index]=null;
};

comboxOperator.deleteOption = function(combox,value)
{
    for(var i=0;i<combox.options.length;i++)
    {
       var option = combox.options[i];
       if(option.value ==  value)
       {
          combox.options[i] = null;
          return;
       }
    }
};

comboxOperator.clearOption = function(combox)
{
    while(combox.options.length>0)
       combox.options[0]=null;
};

comboxOperator.clearSelectedOption = function(combox)
{
    if(combox.options.length > 0)
    {
       for(var i=0;i<combox.options.length;i++)
       {
          var option = combox.options[i];
          if(option.selected)
          {
            combox.options[i]=null;
            i--;
          }
       }
    }
};

comboxOperator.insertOption = function(combox,value,text)
{
    for(var i=0;i<combox.options.length;i++)
    {
       var option = combox.options[i];
       if(option.value ==  value)
          return;
    }

    this.addOption(combox,value,text);
};

comboxOperator.copyOption = function(combox1,combox2)
{
    for(var i=0;i<combox1.options.length;i++)
    {
       var option = combox1.options[i];
       if(option.selected)
          this.insertOption(combox2,option.value,option.text);
    }
};

comboxOperator.copyAllOption = function(combox1,combox2)
{
    for(var i=0;i<combox1.options.length;i++)
    {
       var option = combox1.options[i];
       this.insertOption(combox2,option.value,option.text);
    }
};

comboxOperator.moveOption = function(combox1,combox2)
{
    while(combox1.selectedIndex!=-1)
    {
       var option = combox1.options[combox1.selectedIndex];
       this.insertOption(combox2,option.value,option.text);
       combox1.options[combox1.selectedIndex]=null;
    }
};

comboxOperator.moveAllOption = function(combox1,combox2)
{
    while(combox1.options.length>0)
    {
       var option = combox1.options[0];
       this.insertOption(combox2,option.value,option.text);
       combox1.options[0]=null;
    }
};

comboxOperator.up = function(combox)
{
    var index = combox.selectedIndex
    if(index > 0)
    {
         var text=combox.options[index-1].text;
         var value=combox.options[index-1].value;
         combox.options[index-1].text=combox.options[index].text;
         combox.options[index-1].value=combox.options[index].value;
         combox.options[index-1].selected = true;
         combox.options[index].selected = false;
         combox.options[index].text=text;
         combox.options[index].value=value;
    }
}

comboxOperator.down = function(combox)
{
    var index = combox.selectedIndex
    if(index >= 0 && index < combox.options.length)
    {
         var text=combox.options[index+1].text;
         var value=combox.options[index+1].value;
         combox.options[index+1].text=combox.options[index].text;
         combox.options[index+1].value=combox.options[index].value;
         combox.options[index+1].selected = true;
         combox.options[index].selected = false;
         combox.options[index].text=text;
         combox.options[index].value=value;
    }
}
comboxOperator.top = function(combox)
{
    var index = combox.selectedIndex
    if(index > 0)
    {
         var text=combox.options[index].text;
         var value=combox.options[index].value;
         for(i=index;i>0;i--){
         	combox.options[i].text=combox.options[i-1].text;
        	combox.options[i].value=combox.options[i-1].value;
        }
        combox.options[0].text=text;
        combox.options[0].value=value;
        combox.options[index].selected = false;
        combox.options[0].selected = true;
    }
}
comboxOperator.bottom = function(combox)
{
    var index = combox.selectedIndex
    if(index >= 0)
    {
    		var l=combox.options.length-1;
         var text=combox.options[index].text;
         var value=combox.options[index].value;
         for(i=index;i<l;i++){
         	combox.options[i].text=combox.options[i+1].text;
        	combox.options[i].value=combox.options[i+1].value;
        }
        combox.options[l].text=text;
        combox.options[l].value=value;
        combox.options[index].selected = false;
        combox.options[l].selected = true;
    }
}
comboxOperator.selectAll = function(combox)
{
   var n = combox.options.length;
   for(var i=0;i<n;i++)
      combox.options[i].selected = true;
}
